package com.aic.aicdetactor.util;

public class HexUtil {

	public static int getInt(byte[] bytes) {
		return (0xff & bytes[3]) | (0xff00 & (bytes[2] << 8)) | (0xff0000 & (bytes[1] << 16)) | (0xff000000 & (bytes[0] << 24));
	}

	public static int getInt(byte[] bytes, int position) {
		return (0xff & bytes[position + 3]) | (0xff00 & (bytes[position + 2] << 8)) | (0xff0000 & (bytes[position + 1] << 16)) | (0xff000000 & (bytes[position + 0] << 24));
	}

	public static String toHexString(byte[] bytes) {
		String ret = "";
		for (int i = 0; i < bytes.length; i++) {
			String hex = Integer.toHexString(bytes[i] & 0xFF);
			if (hex.length() == 1) {
				hex = '0' + hex;
			}
			ret += hex.toUpperCase();
		}
		return ret;
	}
}
